import {message} from 'antd'
import router from 'umi/router'

export default {
  onError (e) {
    let msg = e.message
    e.preventDefault()
    console.log("--------------------------------- global error handle -----------------------------")
    console.log(e)
    console.log(e.message)
    console.log(e.code)
    if (e.code === 401) {
      router.push('/login?destroy=true')
    } else if (e.code === 403) {
      router.push('/403')
    } else if (e.code >= 500 && e.code < 600) {
      router.push('/500')
    } else if (e.code > 600) {
      console.warn(e)
      msg = e.msg
    }
    console.log("--------------------------------- global error handle -----------------------------")
    message.error(msg)
  },
}
